<?php

namespace app\common\dao\system\merchant;


use app\common\dao\BaseDao;
use app\common\model\system\merchant\FinancialWechat;

class FinancialWechatDao extends BaseDao
{

    protected function getModel(): string
    {
        return FinancialWechat::class;
    }

    /**
     * @return string
     * @author: fupeng
     * @day: 2024/1/4
     */
    public function getSn()
    {
        list($msec, $sec) = explode(' ', microtime());
        $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
        $orderId = 'sft' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
        return $orderId;
    }


    public function in(array $data, $merId)
    {
        return $this->create($data);
    }

    public function get( $id)
    {
        return ($this->getModel())::getDB()->find($id);
    }

    public function search(array $where)
    {
        $query = $this->getModel()::getDB()
            ->when(isset($where['account_type']) && $where['account_type'] !== '', function ($query) use ($where) {
                $query->whereIn('account_type', $where['account_type']);
            })
            ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
                $query->where('mer_id', $where['mer_id']);
            })
            ->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
                $query->where('uid', $where['uid']);
            })
            ->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
                $query->whereLike('out_request_no', "%{$where['keyword']}%");
            })
            ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
                getModelTime($query, $where['date'], 'create_time');
            })
            ->when((isset($where['start_time']) && $where['start_time'] !== '' && isset($where['end_time']) && $where['end_time'] !== ''), function ($query) use ($where) {
                $query->whereBetween('create_time',[$where['start_time'],$where['end_time']]);
             });
        return $query;
    }
}
